package com.example.myapplication;

import android.annotation.SuppressLint;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.widget.RemoteViews;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @author:weng
 * @data:2022/11/8
 * @description:
 */

public class DigitClock extends AppWidgetProvider {
    private static final String TAG = "DigitClock";
    Timer mTimer=new Timer();
    Context mContext;
    int[] mAppWidgetIds;
    AppWidgetManager mManager;


    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        super.onUpdate(context, appWidgetManager, appWidgetIds);
        mContext=context;
        mManager=appWidgetManager;
        mAppWidgetIds=appWidgetIds;

        for (int i = 0; i < mAppWidgetIds.length; i++) {
            int appWidgetId=mAppWidgetIds[i];
            RemoteViews remoteViews=new RemoteViews(mContext.getPackageName(),R.layout.clock_layout);
            SimpleDateFormat format=new SimpleDateFormat("yyyy-MM--dd HH:mm:ss");
            remoteViews.setTextViewText(R.id.textView,format.format(new Date()));
            mManager.updateAppWidget(mAppWidgetIds,remoteViews);
        }
    }


}